/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmVector.java
 *
 * Created on 03-12-2014, 09:47:49 AM
 */
package Presentacion;

import Negocio.Vector;
import javax.swing.table.DefaultTableModel;
import Negocio.Entero;
/**
 *
 * @author Estudiante
 */
public class FrmVector extends javax.swing.JFrame {

    /** Creates new form FrmVector */
    public FrmVector() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnDimension = new javax.swing.JButton();
        txtDimension = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        G1 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        btnordena = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnDimension.setText("DIMENSIONAR");
        btnDimension.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDimensionActionPerformed(evt);
            }
        });

        jLabel1.setText("Dimension");

        G1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(G1);

        jLabel2.setText("VECTORES");

        btnordena.setText("ordenar");
        btnordena.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnordenaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                        .addComponent(txtDimension, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addComponent(btnDimension))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)))
                .addGap(37, 37, 37))
            .addGroup(layout.createSequentialGroup()
                .addGap(150, 150, 150)
                .addComponent(jLabel2)
                .addContainerGap(236, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(btnordena)
                .addContainerGap(367, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDimension)
                    .addComponent(txtDimension, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnordena)
                .addContainerGap(162, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
private void Dimensionar(int Cantidadcolumna){
DefaultTableModel modelo=new DefaultTableModel();
this.G1.setModel(modelo);
for(int i=0;i<=Cantidadcolumna-1;i++){
    modelo.addColumn(Integer.toString(i));
}
Object[]fila=new Object[1];
modelo.addRow(fila);

}
    private void btnDimensionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDimensionActionPerformed
        // TODO add your handling code here:
        
        this.Dimensionar(Integer.parseInt(this.txtDimension.getText()));
    }//GEN-LAST:event_btnDimensionActionPerformed
private void CargarVector(Negocio.Vector ObjVector){
    for(int i=0;i<=Integer.parseInt(this.txtDimension.getText())-1;i++){
     Entero ObjEntero=new Entero();
     ObjEntero.setNum(Integer.parseInt(G1.getValueAt(0, 1).toString()));
     ObjVector.insertar_vector(ObjEntero);
    }
}
private void MostrarVector(Vector ObjVector){
this.Dimensionar(ObjVector.getN());
for(int i=0;i<=ObjVector.getN()-1;i++){
G1.setValueAt(ObjVector.leer_vector(i).getNum(),0,i);
}
}

    private void btnordenaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnordenaActionPerformed
        // TODO add your handling code here:
        
        Negocio.Vector objVector=new Vector();
        this.CargarVector(objVector);
        objVector.Ordenar();
        this.MostrarVector(objVector);
    }//GEN-LAST:event_btnordenaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrmVector().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable G1;
    private javax.swing.JButton btnDimension;
    private javax.swing.JButton btnordena;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField txtDimension;
    // End of variables declaration//GEN-END:variables
}
